using System.Data;
using HKB.Common;
using System;
using System.Web;
using HKB.Data;

namespace HKB.Web.Shop.Member
{
	public class Member : Shop
	{
		public Member()
		{
			if (!base.user.CheckUserLogin())
			{
				string text = Fetch.CurrentUrl;
				if (text != string.Empty)
				{
					text = "?ComeUrl=" + text + "&&lo=2";
				}
				HttpContext.Current.Response.Redirect(this.InstallDir + "Passport/Login.aspx" + text);
				HttpContext.Current.Response.End();
			}
		}
		protected override void WriteErrMsg(string errType, string msg, string ComeUrl)
		{
			if (errType == "")
			{
				errType = Language.Get("Common/ErrTitle");
			}
			string newValue;
			if (ComeUrl != "")
			{
				newValue = "<a id=\"Button\" href='" + ComeUrl + "'>确定</a>";
			}
			else
			{
				newValue = "<a id=\"Button\" href='javascript:history.back();'>返回</a>";
			}
			string text = Template.GetTemplate(Template.GetTemplatePath("MemberError"));
			text = text.Replace("{$Title}", errType);
			text = text.Replace("{$Msg}", msg);
			text = text.Replace("{$Button}", newValue);
			text = text.Replace("{$ComeUrl}", ComeUrl);
			HttpContext.Current.Response.Write(text);
			this.Finish();
			HttpContext.Current.Response.End();
		}
		protected override void WriteSuccessMsg(string errType, string msg, string ComeUrl)
		{
			if (errType == "")
			{
				errType = Language.Get("Common/SuccessTitle");
			}
			string newValue;
			if (ComeUrl != "")
			{
				newValue = string.Concat(new string[]
				{
					"<a id=\"Button\" href='",
					ComeUrl,
					"'>",
					Language.Get("Common/Qieding"),
					"</a>"
				});
			}
			else
			{
				newValue = "<a id=\"Button\" href='javascript:history.back();'>" + Language.Get("Common/Back") + "</a>";
			}
			string text = Template.GetTemplate(Template.GetTemplatePath("MemberSuccess"));
			text = text.Replace("{$Title}", errType);
			text = text.Replace("{$Msg}", msg);
			text = text.Replace("{$Button}", newValue);
			text = text.Replace("{$ComeUrl}", ComeUrl);
			HttpContext.Current.Response.Write(text);
			this.Finish();
			HttpContext.Current.Response.End();
		}

        protected string GetRemindMe()
        {
            int userID = base.user.UserID;
            string text = DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00";

            string str = string.Concat(new object[]
		{
			" (userid=",
			userID,
			" and inputTime>'",
			text,
			"'  and hlshop_order.OrderFormID=HLShop_OrderItem.OrderFormID)"
		});
            string str2 = string.Concat(new object[]
		{
			" or (inputTime>'",
			text,
			"0' and userid=",
			userID,
			" and DateDiff(s,UpdateTime,getdate())>=0 and hlshop_order.OrderFormID=HLShop_OrderItem.OrderFormID)"
		});
            string sQLString = "select hlshop_order.OrderFormID,hlshop_order.OrderFormNum,Status,DeliverStatus,PayStatus,BuyerReview,InputTime from hlshop_order,HLShop_OrderItem where " + str + str2;

            int count = 0;
            DataTable dataTable = DbHelperSQL.GetDataTable(sQLString);
            if (dataTable != null && dataTable.Rows.Count > 0)
            {
                DataRow[] array = dataTable.Select(" Status=1");
                if (array != null)
                {
                    count += array.Length;
                }
                DataRow[] array2 = dataTable.Select(" Status=0");
                if (array2 != null)
                {
                    count += array2.Length;
                }
            }
            return count.ToString();
        }
	}
}
